package com.xpqh.ksg.modular.colorchange.controller;

import com.xpqh.ksg.base.BaseController;
import com.xpqh.ksg.base.BaseResponseDTO;
import com.xpqh.ksg.common.persistence.model.KsgCarColorChange;
import com.xpqh.ksg.common.persistence.model.KsgOverseasCarColor;
import com.xpqh.ksg.modular.colorchange.dto.ColorChangeHistoryReqDTO;
import com.xpqh.ksg.modular.colorchange.dto.ColorChangeListReqDTO;
import com.xpqh.ksg.modular.colorchange.dto.ColorChangeSaveReqDTO;
import com.xpqh.ksg.modular.colorchange.service.ColorChangeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("ksg/colorchange")
public class ColorChangeController extends BaseController {

    @Autowired
    private ColorChangeService colorChangeService;

    /**
     * 获取色卡列表
     * @param req 请求参数
     * @return 色卡列表
     */
    @PostMapping("/color/list")
    public BaseResponseDTO getColorList(@Valid @RequestBody ColorChangeListReqDTO req) {
        List<KsgOverseasCarColor> colorList = colorChangeService.getColorList(req.getPageNo());
        return renderResultOk(colorList);
    }

    /**
     * 用户提交渲染信息
     * @param req 请求参数
     * @return 渲染记录
     */
    @PostMapping("/save")
    public BaseResponseDTO saveColorChange(@Valid @RequestBody ColorChangeSaveReqDTO req) {
        Integer userId = getUserId();
        KsgCarColorChange colorChange = colorChangeService.saveColorChange(req.getCarImgUrl(), req.getColorCardId(), userId);
        return renderResultOk(colorChange);
    }

    /**
     * 获取用户的渲染历史列表
     * @param req 请求参数
     * @return 渲染历史列表
     */
    @PostMapping("/list")
    public BaseResponseDTO getColorChangeHistory(@Valid @RequestBody ColorChangeHistoryReqDTO req) {
        Integer userId = getUserId();
        List<KsgCarColorChange> historyList = colorChangeService.getUserColorChangeHistory(userId, req.getPageNo());
        return renderResultOk(historyList);
    }

}
